<?php
namespace Student\Controller;
use Think\Controller;

class TextController extends Controller
{
    public function checkUsername()
    {
        if (IS_POST) {
            $username = I("username", "", "trim");
            $password = I("password");
            $return = $this->checkPassword($username, $password);
            if ($return) {
                echo "<br>";

                $this->success('登陆成功', 'main');

            } else {
                $this->error('用户密码错误');
            }
        } else {
            $this->display();
        }
    }

    public function checkPassword($username, $password)
    {
        $map['username'] = $username;
        $admin = M('admin')->where($map)->find();
        if ($admin['password'] === $password) {
            return $admin;
        } else {
            return false;
        }
    }

    public function main()
    {
        $this->display();
    }

    public function add()//添加学生数据
    {
        if (IS_POST) {
            $name = I('name');
            $department = I('department');
            $subject = I('subject');
            $score = I('score');
            $time = I('time');
            $data = array(
                'name' => $name,
                'department' => $department,
                'subject' => $subject,
                'score' => $score,
                'time' => $time
            );
            $id = M('class')->add($data);

            if (!$id === false) {
                echo "操作成功，ID为" . $id;
                $this->success('跳转回首页','',1);
            } else {
                echo "操作失败";
            }

        } else {
            $this->display();

        }

    }

    public function find1()//在页面显示表单
    {
        if (IS_POST) {
            $name = I('name');
            $department = I('department');
            $subject = I('subject');
            $score = I('score');
            $time = I('time');
            $data['name'] = array('like', "%{$name}%");//模糊查询
            $data['subject'] = array('like', "%{$subject}%");           //把查询条件传入查询方法
            $data['score'] = array('like', "%{$score}%");
            $data['department'] = array('like', "%{$department}%");
            $data['time'] = array('like', "%{$time}%");

            $list = M("class")->where($data)->select();
            $this->assign("list", $list);
            $this->display();
        } else {
            $this->display();
        }
    }

//以上volist 在页面显示表单


    public function find2()
    {
        if (IS_POST) {
            $name = I('name');
            $department = I('department');
            $subject = I('subject');
            $score = I('score');
            $time = I('time');
            $where['name'] = array('like', "%$name%");
            $where['department'] = array('like', "%$department%");
            $where['subject'] = array('like', "%$subject%");
            $where['score'] = array('like', "%$score%");
            $where['time'] = array('like', "%$time%");

            $list = M("class")->where($where)->select();
            $this->ajaxReturn($list);
//            $this->display(); //这个是显示html界面用的， ajax返回不需要这个，有上面那个就好了


        } else {
            $this->display();
        }

    }


    public function find3()
    {
        if (IS_POST) {
            $name = I('name');
            $department = I('department');
            $subject = I('subject');
            $score = I('score');
            $time = I('time');
            $where['name'] = array('like', "%$name%");
            $where['department'] = array('like', "%$department%");
            $where['subject'] = array('like', "%$subject%");
            $where['score'] = array('like', "%$score%");
            $where['time'] = array('like', "%$time%");

            $list = M("class")->where($where)->select();

            $this->ajaxReturn($list);
//            $this->display(); //这个是显示html界面用的， ajax返回不需要这个，有上面那个就好了


        } else {
            $this->display();
        }

    }

    public function del(){

        $id=I("id");
        $rt = M("class")->where(array("id"=>$id))->delete();//属性=>值
        $data['code'] = 0;
        $data['msg'] = '删除成功';
        if(!$rt){
            $data['code'] = 1;
            $data['msg'] = '删除失败';
        }
        $this->ajaxReturn($data);
    }

public function find4(){
    if(IS_POST){
                $name=I("name");
                $number=I("number");
                $data['name']=array('like',"%$name%");
                $data['number']=array('like',"%$number%");
                $member=M("text")->where($data)->select();
                $this->ajaxReturn($member);
    }else{
        $this->display();
    }
    }

public function delect(){
        $id=I("id");
        $menber=array("id"=>$id);
        $tr=M("text")->where($menber)->delete();
        $data['code']=0;
        $data['msg']="删除成功";
        if(!$tr){
            $data['code']=1;
            $data['msg']="删除失败";
        }
        $this->ajaxReturn($data);
}

public function update(){

}




}


